package com.example.music.controller;

import com.example.music.domain.Tags;
import com.example.music.service.ITagsService;
import com.example.music.util.AjaxResult;
import com.example.music.util.Anonymous;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Anonymous
@Api(tags = "音乐标签信息管理(224 魏川子)")
@RestController
@RequestMapping("/api/Tags")
public class TagsController {
    @Autowired
    private ITagsService tagsService;

    @ApiOperation(value = "获取所有标签信息(224 魏川子)", notes = "获取所有标签信息")
    @GetMapping("/list")
    public AjaxResult list(){
        return AjaxResult.success(tagsService.getTags());
    }

    @ApiOperation(value = "根据名字获取标签信息(224 魏川子)", notes = "根据名字获取标签信息")
    @GetMapping("/getTagsByName/{tName}")
    public AjaxResult getTagsByName(@PathVariable("tName") String tName){
        return AjaxResult.success(tagsService.selectTagsByName(tName));
    }

    @ApiOperation(value = "根据id获取标签信息(224 魏川子)", notes = "根据id获取标签信息")
    @GetMapping("/{id}")
    public AjaxResult getTagsById(@PathVariable("id") Long id){
        return AjaxResult.success(tagsService.selectTagsById(id));
    }

    @ApiOperation(value = "新增标签信息(224 魏川子)", notes = "新增标签信息")
    @PostMapping("/insert")
    public AjaxResult insertTags(@RequestBody Tags tags){
        return AjaxResult.success(tagsService.insertTags(tags));
    }

    @ApiOperation(value = "更新标签信息(224 魏川子)", notes = "更新标签信息")
    @PutMapping("/update")
    public AjaxResult updateTags(@Validated @RequestBody Tags tags){
        return AjaxResult.success(tagsService.updateTags(tags));
    }

    @ApiOperation(value = "删除标签信息(224 魏川子)", notes = "删除标签信息")
    @DeleteMapping("/{id}")
    public AjaxResult deleteTags(@PathVariable Long id){
        return AjaxResult.success(tagsService.deleteTags(id));
    }
}
